package com.Leetcode;

import com.structure.ListNode;
import com.Util.ProduceListNode;

public class Index206reverseList {
	public ListNode reverseList(ListNode head) {
		if(head == null || head.next == null) return head;
        ListNode p = head.next,q = head.next.next;
        head.next = null;
        while(q != null) {
        	p.next = head;
        	head = p;
        	p = q;
        	q = q.next;
        }
        p.next = head;
        return p;
    }
	
	public static void main(String[] args){
    	String line = "[1,2,3,4,5]";
    	ListNode head = ProduceListNode.stringToListNode(line);
        Index206reverseList index206 = new Index206reverseList();
        ListNode ret = index206.reverseList(head);
        String out = ProduceListNode.listNodeToString(ret);
        System.out.println(out);
	}
}

